import { JsonController, Get } from 'routing-controllers';
import { create } from 'svg-captcha';
import { Code, CodeMessage } from '../utils/code';
import { Result } from '../utils/result';

@JsonController('/captcha')
export class CaptchaController {
  @Get('')
  async getCaptcha() {
    const data = create();
    if (data) {
      return Result.ok(Code.SUCCESS, CodeMessage[Code.SUCCESS], data);
    }
    return Result.fail(Code.ERROR, CodeMessage[Code.ERROR]);
  }
}
